/**
 * 面对面建群业务 type 5
 * 第一版 根据创建时间和数字区分
 * 互联网 输入相同数字就可以进入
 */

const onfacetoface = (Item) => {
	let obj = {
		code: 200,
		type: 5,
		status: true, //群聊失效false,反之 true
		message: "面对面建群"
	}
	OperationfaceToFaceTime();
	if (!Item.fromId || Item.fromName === undefined || Item.groupNumber === undefined) {
		return;
	}
	let {
		groupNumber
	} = Item;
	if (faceToFaceList[groupNumber] === undefined) {
		faceToFaceList[groupNumber] = {
			groupNumber: groupNumber,
			ItemId: (new Date()).getTime(),
			arr: new Map(),
			url: "", //群图标
			describe: `[ID:${Item.fromId}-username:${Item.fromName}]创建`,
			userlist: [],
			intoUserList:new Set(),
			onlineTime: new Date()
		}
	} else {
		//已经有群信息，重置时间
		faceToFaceList[groupNumber].onlineTime = new Date();
	}

	faceToFaceList[groupNumber].arr.set(Item.fromId, Item);
	faceToFaceList[groupNumber].userlist = [];
	faceToFaceList[groupNumber].arr.forEach((value, key) => {
		faceToFaceList[groupNumber].userlist.push(value)
	})

	obj.data = Object.assign({}, faceToFaceList[groupNumber]);
	// 群发
	faceToFaceList[groupNumber].arr.forEach((value, key) => {
		if (wsClients[key]) {
			wsClients[key].forEach((client) => {
				client.send(JSON.stringify(obj));
			});
		}
	})
}
module.exports = onfacetoface;